﻿namespace HCore
{
    public enum GoalStatus
    {
        Active,
        Inactive,
        Completed,
        Failed
    }

    public abstract class Goal<T>
    {
        public int goalType => _goalType;

        protected readonly T _owner;
        protected readonly int _goalType;
        protected GoalStatus _status;

        public Goal(T owner, int goalType)
        {
            _owner = owner;
            _goalType = goalType;
            _status = GoalStatus.Inactive;
        }

        protected void ActivateIfInactive()
        {
            if (isInactive())
            {
                Activate();
            }
        }

        protected void ReactivateIfFailed()
        {
            if (hasFailed())
            {
                _status = GoalStatus.Inactive;
            }
        }

        public abstract void Activate();

        public abstract GoalStatus Process();

        public abstract void Terminate();

        public virtual bool HandleMessage(Telegram msg)
        {
            return false;
        }

        public bool isComplete()
        {
            return _status == GoalStatus.Completed;
        }

        public bool isActive()
        {
            return _status == GoalStatus.Active;
        }

        public bool isInactive()
        {
            return _status == GoalStatus.Inactive;
        }

        public bool hasFailed()
        {
            return _status == GoalStatus.Failed;
        }
    }
}